﻿using System;
using System.Configuration;
using FellowshipOne.API.Base;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FellowshipOne.API.Tests
{
    [TestClass]
    public class Base
    {
        public RestClient Client;
        public F1OAuthTicket Ticket;

        [TestInitialize]
        public void Setup() {
            IFellowshipOneClient fellowshipOneClient = new FellowshipOneClient();
            F1OAuthTicket ticket = new F1OAuthTicket
            {
                ConsumerKey = ConfigurationManager.AppSettings["Consumer.Key"],
                ConsumerSecret = ConfigurationManager.AppSettings["Consumer.Secret"],
                ChurchCode = ConfigurationManager.AppSettings["Church.Code"],
                PersonURL = "http://tests.com"
            };
            F1OAuthTicket requestTokenAuthTicket = fellowshipOneClient.GetRequestToken(ticket, true, true);

            Ticket = fellowshipOneClient.Authorize(requestTokenAuthTicket,
                ConfigurationManager.AppSettings["Username"], ConfigurationManager.AppSettings["Password"], LoginType.PortalUser, true);

            Client = new RestClient(Ticket, ConfigurationManager.AppSettings["API.Url"], true, false);
        }

        [TestCleanup]
        public void TearDown() {
            Ticket = null;
            Client = null;
        }
    }
}
